//
//  BDNodeModel.m
//  SmallEasyLife
//
//  Created by qianfeng on 15/10/24.
//  Copyright © 2015年 GXK. All rights reserved.
//

#import "BDNodeModel.h"
#import "Event.h"
#import "Themes.h"

@implementation BDNodeModel

+ (instancetype)bdNodeModelWithDictionary:(NSDictionary *)dictionary
{
    return [[self alloc] initWithNodeDictionary:dictionary];
}

- (instancetype)initWithNodeDictionary:(NSDictionary *)dictionary
{
    if (self = [super init]) {
        NSString *dateString = dictionary[@"date"];
        NSDateFormatter *dateFormate = [[NSDateFormatter alloc] init];
        [dateFormate setDateFormat:@"YYYY-MM-dd"];
        NSDate *currentDate = [dateFormate dateFromString:dateString];
        [dateFormate setDateStyle:NSDateFormatterMediumStyle];
        NSString *stringDate = [dateFormate stringFromDate:currentDate];
        NSArray *arr = [stringDate componentsSeparatedByString:@","];
        self.date = arr[0];
        NSArray * eventsArray = dictionary[@"events"];
        NSMutableArray * eventsModelsMArr = [[NSMutableArray alloc] initWithCapacity:eventsArray.count];
        for (NSInteger i = 0 ; i < eventsArray.count ; ++i) {
            
            Event * eventModel = [Event eventWithDictionary:eventsArray[i]];
            [eventsModelsMArr addObject:eventModel];
            
        }
        self.events = eventsModelsMArr;
        
        
        NSArray * themesArray = dictionary[@"themes"];
        NSMutableArray * themesModelsMArr = [[NSMutableArray alloc] initWithCapacity:themesArray.count];
        for (NSInteger i = 0 ; i < themesArray.count ; ++i) {
            
            Themes * themeModel = [Themes themesWithDictionary:themesArray[i]];
            [themesModelsMArr addObject:themeModel];
        }
        self.themes = themesModelsMArr;
        
    }
    return self;
}
- (NSString *)description
{
    return [NSString stringWithFormat:@"date:%@, events:%@, themes:%@",self.date,self.events,self.themes];
}


- (float)contentHeight
{
    if (self.themes.count <1) {
        return 275;
    }
    return 481;
}

@end
